//此为定位页面所用
authApp.value('page','report_fill');

/*controller部分*/

//主要操作controller
authApp.controller("opinionEditController",function($scope,$http,$getQueryString,$timeout,$sce,Upload){
	$scope.zgbg=$sce.trustAsHtml("上传电子版");
	//查询整改报告
	var queryMainApi=apis.queryAuthRectificationReport;	
	$scope.queryMain=function(){
		$http({
			method:'get',
			url:queryMainApi,
			params:{},
		}).success(function(response){
			if(response.code=="000000"){
				if(response.data.data != "0" && !response.data.data){
					$scope.zgbg=$sce.trustAsHtml(response.data.fileName);
				}
			}else{
				alert(response.errorMsg);
			}
		}).error(function(){
			alert("网络出现故障，请确认网络是否连接");
		})
	}
	$scope.queryMain();
	
	
	//整改报告上传
	$scope.uploadFiles= function(file, errFiles,index) {
        $scope.f = file;
        $scope.errFile = errFiles && errFiles[0];
        if (file) {
            file.upload = Upload.upload({
                url: apis.uploadReport,
                data: {file: file}
            });

            file.upload.then(function (response) {
                $timeout(function () {
                	if(response.data.code=="000000"){
                		$scope.zgbg=$sce.trustAsHtml(file.name);
                		$scope.savePath(response.data.data,file.name);  
                	}
                	else
                		alert(response.data.errorMsg);
                });
            }, function (response) {
                if (response.status > 0)
                    $scope.errorMsg = response.status + ': ' + response.data;
            }, function (evt) {
                file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
            });
        }
    }
	
	//保存地址path
	$scope.savePath=function(filePath,filename){
		$http({
			method:'post',
			url:apis.saveAuthRectificationReport,
			data:{filepath:filePath,filename:filename},
		}).success(function(response){
			if(response.code=="000000"){
				
			}else{
				alert(response.errorMsg);
			}
		}).error(function(){
			alert("网络出现故障，请确认网络是否连接");
		})
	}
})
